<!-- <template>
    <div>
        <input placeholder="请输入">
        <button @click="sent()">发送</button>
        <div id="text"></div>
    </div>
</template>
<script>
export default {
    name: "Chat",
    data() {
        return {
            websocket: '',
            text:''
        }
    },
    created() {
        this.websocket = new WebSocket(
            "ws://39.98.162.10:8080/websocket/2"
        )
        var div = document.querySelector("div")
        this.websocket.addEventListener('message', function (e) {
           div.innerHTML=+e.data+'<br>'
        })
    },
    methods: {
        sent() {
            var input = document.querySelector('input').value
            var obj = {
                id: 2,
                msg: input,
                type: "kefu",
                to: 1
            }
            this.websocket.send(JSON.stringify(obj))
        }
    }
}
</script>
<style></style>

 -->
<template>
  <el-container>
    <el-aside width="auto" style="background-color: #040f42; height: 747px">
      <el-dropdown @command="handleCommand"
        v-if="user !== ''">
        <span class="el-dropdown-link">
          <el-image
            style="
              width: 35px;
              height: 35px;
              margin-left: 16px;
              margin-top: 15px;
              margin-bottom: 5px;
              border-radius: 50px;
            "
            :src="user.image"
            fit="fit"
          ></el-image>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">退出</el-dropdown-item>
          <el-dropdown-item divided command="b">个人信息</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

      <el-menu
        default-active="1-4-1"
        class="el-menu-vertical-demo"
        @select="handleOpen"
        @close="handleClose"
        :collapse="isCollapse"
        background-color="#040f42"
        text-color="#fff"
        active-text-color="#ffd04b"
      >
        <el-menu-item index="index">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="msg">
          <i class="el-icon-chat-dot-square"></i>
          <span slot="title">消息</span>
        </el-menu-item>
        <el-menu-item index="3">
          <i class="el-icon-document"></i>
          <span slot="title">导航三</span>
        </el-menu-item>
        <el-menu-item :index="'4' + item" v-for="item in 8" :key="item">
          <i class="el-icon-document"></i>
          <span slot="title">待开发</span>
        </el-menu-item>
        <el-menu-item index="4">
          <i class="el-icon-setting"></i>
          <span slot="title">设置</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header
        height="42px"
        style="
          background-color: rgb(255, 255, 255);
          border-bottom: 1px solid #dbdcdf;
        "
      >
        <el-row>
          <el-col :span="21">
            <div>
              <el-dropdown @command="click">
                <span class="el-dropdown-link">
                  <i class="el-icon-s-comment a" :style="'color:' + color"></i>
                  <span style="margin-top: 10px">
                    {{ status }}<i class="el-icon-caret-bottom"></i
                  ></span>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <div
                    style="
                      display: flex;
                      align-items: center;
                      justify-content: center;
                    "
                  >
                    <div
                      style="
                        width: 8px;
                        height: 8px;
                        background-color: #15c292;
                        border-radius: 50px;
                        margin-left: 20px;
                      "
                    ></div>
                    <el-dropdown-item style="margin-left: -15px" command="1"
                      >在线</el-dropdown-item
                    >
                  </div>

                  <div
                    style="
                      display: flex;
                      align-items: center;
                      justify-content: center;
                    "
                  >
                    <div
                      style="
                        width: 8px;
                        height: 8px;
                        background-color: #c2ab15;
                        border-radius: 50px;
                        margin-left: 20px;
                      "
                    ></div>
                    <el-dropdown-item style="margin-left: -15px" command="0"
                      >离线</el-dropdown-item
                    >
                  </div>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
          <el-col :span="3">
            <div style="font-size: 19px; margin-top: 10px">
              <i class="el-icon-s-comment"></i
              ><span style="font-size: 15px; margin-left: 5px">短信</span>

              <i
                class="el-icon-service"
                style="margin-left: 25px; margin-right: 12px"
              ></i>
              <i class="el-icon-warning-outline"></i>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <el-main style="padding: 0">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
  
<script>
import { RouterView } from "vue-router";
import Cookies from "js-cookie";
export default {
  data() {
    return {
      user: "",
      status: "",
      color: "",
      url: "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
      isCollapse: true,
    };
  },
  created() {
    this.getstatus();
  },
  methods: {
    handleCommand(command) {
       if(command==='a'){
        Cookies.remove("kefu")
        this.$router.push({ name: "home" }, (onComplete) => {},(onAbort) => {});

       }
      },
    getstatus() {
      var user = Cookies.get("kefu");
      if (user === "" || user === null || user === undefined) {
        this.$router.push({ name: "home" }, (onComplete) => {},(onAbort) => {});

      }
      this.user = JSON.parse(user);
      var id = this.user.id;
      var status = this.user.status;
      if (status === 1 || status === "1") {
        this.status = "在线";
        this.color = "#15c292";
      } else {
        this.status = "离线";
        this.color = "#c2ab15";
      }
    },
    click(command) {
      this.user.status = command;
      Cookies.remove("kefu");
      Cookies.set("kefu", JSON.stringify(this.user));
      if (command === "1") {
        this.status = "在线";
        this.color = "#15c292";
      } else {
        this.status = "离线";
        this.color = "#c2ab15";
      }
      this.$http
        .get("/kefu/xiuxi?id=" + this.user.id + "&status=" + command)
        .then((res) => {});
      this.$message.success(command === "1" ? "在线成功" : "离线成功");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
      if (key === "index" || key === "msg") {
        if (this.$route.name !== key) {
          this.$router.push(key);
        }
      }
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
  components: { RouterView },
};
</script>
<style>
.a {
  font-size: 18px;
  margin-top: 13px;
}
</style>